<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://displaytag.sf.net/el" prefix="display-el" %>
<%@ taglib uri="ford-arg/tags" prefix="ft" %>


<script language="javascript">

	function findPaymentPolicies() {
		document.PaymentPolicyForm.action = "PaymentPolicyActionFind.do";
		document.PaymentPolicyForm.section.value = "find";
		document.PaymentPolicyForm.submit();
	}
	
	function clearFindFilds(){
		document.PaymentPolicyForm.section.value = "cleanFind";
		document.getElementById('supplierClass').selectedIndex=0;
		document.getElementById('supplierCode').value="";
		document.getElementById('itemCategory').selectedIndex=0;
		document.getElementById('item').selectedIndex=0;
	}
	
	function newPaymentPolicy(){
		document.PaymentPolicyForm.action = "PaymentPolicyActionNew.do";
		document.PaymentPolicyForm.section.value = "newPayPol";
		document.PaymentPolicyForm.submit();					
	}
	
	function newVersion(){
		document.PaymentPolicyForm.action = "PaymentPolicyActionNewVersion.do";
		document.PaymentPolicyForm.section.value = "newVersion";
		document.PaymentPolicyForm.submit();					
	}
	
	function backToFullEconomics(){
		document.PaymentPolicyForm.action = "PaymentPolicyActionBackToFullEconomics.do";
		document.PaymentPolicyForm.section.value = "newVersion";
		document.PaymentPolicyForm.submit();
	}
	
	function editVersion(){
		document.PaymentPolicyForm.action = "PaymentPolicyActionEdit.do";
		document.PaymentPolicyForm.section.value = "editVersion";
		document.PaymentPolicyForm.submit();						
	}
	
	function deleteVersion(){
		document.PaymentPolicyForm.action = "PaymentPolicyActionDelete.do";
		document.PaymentPolicyForm.section.value = "delete";
		document.PaymentPolicyForm.submit();						
	}
	
	function approveAll(){
		document.PaymentPolicyForm.action = "PaymentPolicyActionApproveAll.do";
		document.PaymentPolicyForm.section.value = "approveAll";
		document.PaymentPolicyForm.submit();						
	}
	
	function selectOne(num){
		for(i=0; i<document.PaymentPolicyForm.elements.length; i++){
			var elemento = document.PaymentPolicyForm.elements[i];
			if(elemento.name=='selectedPpIndex'){
				if(elemento.value != num)
					elemento.checked=false;
			}						
		}
	} 
	
	function findItems( options ) {
		var req = null;
		var itemCategory = options[options.selectedIndex].value;
		
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			try {
				req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					req = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
				}
			}
		}
		req.onreadystatechange = function( ) {
			if (req.readyState == 4) {
				document.getElementById("item").innerHTML = req.responseText;
			}
		};
		req.open("GET", "PaymentPolicyActionFindItems.do?itemCategory="+itemCategory+"&r="+Math.random(), true);
		req.setRequestHeader("Content-Type",
				"application/x-www-form-urlencoded");
		req.send(null);
	}
	
	function propose() {
		document.PaymentPolicyForm.action = "PaymentPolicyActionPropose.do";
		document.PaymentPolicyForm.section.value = "propose";
	}

	function approve() {
		document.PaymentPolicyForm.action = "PaymentPolicyActionApprove.do";
		document.PaymentPolicyForm.section.value = "approve";
	}
	
	
</script>
	
<table>
	<tr>
		<td colspan="2"><h2><bean:message key="paymentPolicy.label.title"/></h2></td>
	</tr>
</table>
<br/>
<html:form action="/PaymentPolicyActionInit">
<html:hidden property="section" />

	<%-- Mantiene el numero de pagina despues del submit --%>
	<ft:saveActivePageNumber/>

	<bean:define id="codeTitle">
		<bean:message key="paymentPolicy.label.tableHeader.code" />
	</bean:define>
	<bean:define id="descriptionTitle">
		<bean:message key="paymentPolicy.label.tableHeader.description" />
	</bean:define>
	<bean:define id="versionTitle">
		<bean:message key="paymentPolicy.label.tableHeader.version" />
	</bean:define>
	<bean:define id="ppValueTitle">
		<bean:message key="paymentPolicy.label.tableHeader.ppValue" />
	</bean:define>
	<bean:define id="prioValueTitle">
		<bean:message key="paymentPolicy.label.tableHeader.priorValue" />
	</bean:define>
	<bean:define id="effDateTitle">
		<bean:message key="paymentPolicy.label.tableHeader.effDate" />
	</bean:define>
	<bean:define id="supplierTitle">
		<bean:message key="paymentPolicy.label.tableHeader.supplier" />
	</bean:define>
	<bean:define id="creationTitle">
		<bean:message key="user.label.creation" />
	</bean:define>
	<bean:define id="proposalTitle">
		<bean:message key="user.label.proposal" />
	</bean:define>
	<bean:define id="approvalTitle">
		<bean:message key="user.label.approval" />
	</bean:define>
	<bean:define id="obsTitle">
		<bean:message key="costStructure.label.tableHeader.obs" />
	</bean:define>
	<bean:define id="selectTitle">
		<bean:message key="label.select" />
	</bean:define>
	<table style="width: 500px;">
		<tr>
			<td class="text_blue_bold align_left" colspan="5">
				<bean:message key="part.label.filter" />
			</td>
		</tr>
		<tr>
			<td class="text_blue_bold align_left">
				<bean:message key="part.label.supplier" />
			</td>
			<td class="text_blue_bold align_left" colspan="2">
				<html:select property="supplierClass" styleId="supplierClass">
					<html:option value="-1"><bean:message key="label.allOption" /></html:option>
					<html:options collection="partClassColl"
								  property="value"
								  labelProperty="label" />
				</html:select>&nbsp;
				<html:text styleId="supplierCode" property="supplierCode" maxlength="50" size="20"/>
			</td>

		</tr>
		<tr>
			<td class="text_blue_bold align_left">
				<bean:message key="costStructure.itemCategory"/>
			</td>
			<td class="text_blue_bold align_left" colspan="1">
				<html:select property="itemCategory" styleId="itemCategory" onchange="findItems(this)">
					<html:option value="-1"><bean:message key="label.allOption" /></html:option>
					<html:options collection="ItemCategoryColl"
								  property="eesc05ItemcatgryNumberK"
								  labelProperty="eesc05ItemcatgryNameN" />
				</html:select>
			</td>
			<td class="text_blue_bold align_left">
				<bean:message key="costStructure.item" />
			</td>
			<td class="text_blue_bold align_center" colspan="2">
			<div id="item">
				<html:select property="item" styleId="item">
					<html:option value="-1"><bean:message key="label.allOption" /></html:option>
					<html:options collection="itemColl"
								  property="eesc06ItemNumberK"
								  labelProperty="eesc06ItemNameN" />
				</html:select>
			</div>
			</td>
			<td class="text_blue_bold align_right">
			</td>
		</tr>
		<tr>
			<td class="align_left" colspan="3">
				<html:checkbox property="aprovedOnesOnly" value="true" onclick=""></html:checkbox>
				<bean:message key="paymentPolicy.label.showLastApprovedOnly"/>
			</td>
			<td class="text_blue_bold align_right" style="width: 10%">
				<html:button property="find" onclick="findPaymentPolicies();" styleClass="button"><bean:message key="label.find" /></html:button>
			</td>
			<td class="align_right"  style="width: 75px;">			
				<input type="button" value="<bean:message key="label.clean"/>" class="button" onclick="clearFields()" />
			</td>
		</tr>	
	</table>
	<br/>		
	<table style="width: 900px;" class="no_border" cellspacing="5">
		<tr>
			<td class="text_blue_bold align_left">
				<html:button property="newPayPol" onclick="newPaymentPolicy();" styleClass="button"><bean:message key="paymentPolicy.label.new" /></html:button>&nbsp;
				<html:button property="newVers" onclick="newVersion();" styleClass="button"><bean:message key="paymentPolicy.label.newVersion" /></html:button>&nbsp;
				<html:button property="editVers" onclick="editVersion();" styleClass="button"><bean:message key="label.edit" /></html:button>&nbsp;
				<html:button property="deleteVers" onclick="deleteVersion();" styleClass="button"><bean:message key="label.delete" /></html:button>
				<logic:notEmpty name="PaymentPolicyForm" property="fullEconomic"><html:button property="backToFullE" onclick="backToFullEconomics();" styleClass="button"><bean:message key="paymentPolicy.label.backToFullEconomics" /></html:button></logic:notEmpty>
			</td>
			<td class="text_blue_bold align_right">
				<html:button property="apprAll" onclick="approveAll()" styleClass="button"><bean:message key="label.aporoveAll" /></html:button>
			</td>
		</tr>	
	</table>
	<table class="no_border" style="width: 900px;">
		<tr>
			<td>
				<display-el:table 	class="table1" style="width: 900px;" cellpadding="5" uid="payPolVersion"
									 pagesize="15" name="sessionScope.PaymentPolicyForm.payPolVersCol" 
									excludedParams="*" requestURI="PaymentPolicyActionPaginate.do" >
					<display-el:column title="${codeTitle}" property="displayVersion.teese04Paypolicy.eese04PaypolNumberK" style="width: 18%;" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right"/>
					<display-el:column title="${descriptionTitle}" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right">
						<logic:notEmpty name="payPolVersion" property="displayVersion.teese04Paypolicy.teesc06Item">
							<bean:write name="payPolVersion" property="displayVersion.teese04Paypolicy.teesc06Item.eesc06ItemNameN"/>
						</logic:notEmpty>
						<logic:empty name="payPolVersion" property="displayVersion.teese04Paypolicy.teesc06Item">
							<bean:write name="payPolVersion" property="displayVersion.teese04Paypolicy.teesc05Itemcatgry.eesc05ItemcatgryNameN"/>
						</logic:empty>
					</display-el:column>
					<display-el:column title="${versionTitle}" property="displayVersion.eese05PpyverVersionNumberK" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right"/>
					<display-el:column title="${ppValueTitle}" property="displayVersion.eese05PpyverPercentP" class="cell1 text_bold border1_right border1_top align_center" headerClass="header border_right"/>
					<display-el:column title="${prioValueTitle}" class="cell1 text_bold border1_right border1_top align_center" headerClass="header border_right">
						<logic:notEmpty name="payPolVersion" property="previousValue">
							<bean:write name="payPolVersion" property="previousValue"/>
						</logic:notEmpty>
						<logic:empty name="payPolVersion" property="previousValue">
							-
						</logic:empty>
					</display-el:column>
					<display-el:column title="${effDateTitle}" property="displayVersion.eese05PpyverInDateY" decorator="ar.com.ford.it.fullEconomics.view.displaytag.DateDecorator"  style="width: 10%;"  class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right" />
					<display-el:column title="${supplierTitle}" style="width: 10%;"  class="cell1 text_bold border1_right border1_top align_center" headerClass="header border_right">
						<logic:notEmpty name="payPolVersion" property="displayVersion.teese04Paypolicy.teess01Supplier">
							<bean:write name="payPolVersion" property="displayVersion.teese04Paypolicy.teess01Supplier.eess01SupplierNameN"/>
						</logic:notEmpty>
						<logic:empty name="payPolVersion" property="displayVersion.teese04Paypolicy.teess01Supplier">*</logic:empty>
					</display-el:column>
					<display-el:column title="${creationTitle}" decorator="ar.com.ford.it.fullEconomics.view.displaytag.CostStructureItemColumnDecorator" class="cell1 text_bold border1_right border1_top align_center" headerClass="header border_right" >
						<bean:write name="payPolVersion" property="displayVersion.eese05CreateUserC"/><br />
						<bean:write name="payPolVersion" property="displayVersion.eese05CreateS"/>
					</display-el:column>
					<display-el:column title="${proposalTitle}" decorator="ar.com.ford.it.fullEconomics.view.displaytag.CostStructureItemColumnDecorator" class="cell1 text_bold border1_right border1_top align_center" headerClass="header border_right" >
						<logic:empty name="payPolVersion" property="displayVersion.eese05PpyverProposalUserC">
							<html:submit property="payPolMapped(${payPolVersion_rowNum})" styleClass="button" onclick="propose();"><bean:message key="label.propose" /></html:submit>
						</logic:empty>
						<logic:notEmpty name="payPolVersion" property="displayVersion.eese05PpyverProposalUserC">
							<bean:write name="payPolVersion" property="displayVersion.eese05PpyverProposalUserC"/><br />
							<bean:write name="payPolVersion" property="displayVersion.eese05PpyverProposalS"/>
						</logic:notEmpty>
					</display-el:column>
					<display-el:column title="${approvalTitle}" decorator="ar.com.ford.it.fullEconomics.view.displaytag.CostStructureItemColumnDecorator" class="cell1 text_bold border1_right border1_top align_center" headerClass="header border_right" >
						<logic:empty name="payPolVersion" property="displayVersion.eese05PpyverProposalUserC">-</logic:empty>
						<logic:notEmpty name="payPolVersion" property="displayVersion.eese05PpyverProposalUserC">
							<logic:empty name="payPolVersion" property="displayVersion.eese05PpyverApprovalUserC">
								<html:submit property="payPolMapped(${payPolVersion_rowNum})" styleClass="button" onclick="approve();"><bean:message key="label.approve" /></html:submit>
							</logic:empty>
							<logic:notEmpty name="payPolVersion" property="displayVersion.eese05PpyverApprovalUserC">
								<bean:write name="payPolVersion" property="displayVersion.eese05PpyverApprovalUserC"/><br />
								<bean:write name="payPolVersion" property="displayVersion.eese05PpyverApprovalS"/>
							</logic:notEmpty>
						</logic:notEmpty>
					</display-el:column>
					<display-el:column title="${obsTitle}" class="cell1 text_bold border1_right border1_top align_center" headerClass="header border_right">
						<logic:empty name="payPolVersion" property="displayVersion.eese05PpyverCommentsX">
							&nbsp;
						</logic:empty>
						<logic:notEmpty name="payPolVersion" property="displayVersion.eese05PpyverCommentsX">
							<div align="center"><html:img src="images/observation.gif" /></div>
						</logic:notEmpty>		
					</display-el:column>
					<display-el:column title="${selectTitle}" class="cell1 text_bold border1_right border1_top align_center" headerClass="header border_right">
						<html:checkbox property="selectedPpIndex" value="${payPolVersion_rowNum}" onclick="selectOne(${payPolVersion_rowNum});"></html:checkbox>
					</display-el:column>
				</display-el:table>
			</td>		
		</tr>
	</table>
</html:form>